using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;


public class SceneMgr : BaseSingletonAutoMono<SceneMgr>
{

    private SceneStateBase currentSceneState;

    private int currentSceneIndex;

    private List<SceneStateBase> sceneStates = new List<SceneStateBase>();

    private void Awake()
    {
        sceneStates.Add(new Scene1());
        sceneStates.Add(new Scene2());
        sceneStates.Add(new Scene3());
        sceneStates.Add(new Scene4());
        sceneStates.Add(new Scene5());
    }

    private void ChangeState(SceneStateBase newState)
    {
        if(currentSceneState != null)
        {
            currentSceneState.ExitScene(); 
        }

        currentSceneState = newState;
        currentSceneState.EnterScene();
        currentSceneState.OnScene();
    }

    public void StartGameScene()
    {
        if(sceneStates.Count == 0)
        {
            Debug.LogError($"[SceneMgr] no sceneStates");
            return;
        }
        ChangeState(sceneStates[0]);
    }

    public void NextScene()
    {
        currentSceneIndex += 1;
        currentSceneIndex %= sceneStates.Count;

        ChangeState(sceneStates[currentSceneIndex]);
    }

    public void PreScene()
    {
        currentSceneIndex = currentSceneIndex + sceneStates.Count - 1;
        currentSceneIndex %= sceneStates.Count;
        ChangeState(sceneStates[currentSceneIndex]);
    }

}



public class SceneStateBase
{
    protected string sceneName;

    public virtual void EnterScene()
    {
        Debug.Log($"[SceneStateBase] EnterScene {sceneName}");
    }

    public virtual void ExitScene()
    {
        Debug.Log($"[SceneStateBase] ExitScene {sceneName}");
    }

    public void OnScene()
    {
        Debug.Log($"[SceneStateBase] OnScene {sceneName}");
        SceneManager.LoadScene(sceneName);
    }
}


public enum eSecnesType
{
    Scene1 = 0,
    Scene2 = 1,
    Scene3 = 2,
    Scene4 = 4,
    Scene5 = 5,
}